home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / eTLiteral.subproj / eTLiteral.m < prev    next >
Encoding:
Text File  |  1995-02-04  |  4.9 KB  |  185 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //    FILENAME:    eTLiteral.m
  3. //    SUMMARY:    Implementation of escaped sequences for different formats
  4. //    SUPERCLASS:    eTImage
  5. //    INTERFACE:    None
  6. //    PROTOCOLS:    <Annotation,HTMDSupport,ASCIISupport,LaTeXSupport,Tool,
  7. //                InspectableTarget>
  8. //    AUTHOR:        Rohit Khare
  9. //    COPYRIGHT:    (c) 1994 California Institure of Technology, eText Project
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //  DESCRIPTION
  12. //        Container of rtf comment, owner, and last-modified date strings.
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //    HISTORY
  15. //    10/30/94:    Modified to support <InspectableTarget>
  16. //    07/25/94:    Added ISINDEX subclass as an investigation into "shortcut"s
  17. //  07/24/94:    Birth
  18. ///////////////////////////////////////////////////////////////////////////////
  19.  
  20. #import"eTLiteral.h"
  21. #define _eTLiteralVERSION    10
  22.  
  23. @implementation eTLiteral
  24. //int    numReps
  25. //char     **theReps
  26. //int     *theFormats
  27.  
  28. -(int) numReps
  29.     {return NUM_FMTS_WRITTEN;}
  30. -(const char **) theReps
  31.     {return theReps;}
  32. -(const char *) theRepForFormat: (int) format
  33.     {return theReps[format];}
  34. -setTheRep: (const char *) newRep forFormat: (int) format
  35. {
  36.     if(!newRep) return self;
  37.     theReps[format] = realloc(theReps[format],(strlen(newRep)+1)*sizeof(char));
  38.     strcpy(theReps[format],newRep);
  39.     return self;
  40. }
  41.  
  42.  
  43. -setRep: (int) theFormat fromStream: (NXStream *)stream length:(int)length
  44. {
  45.     theReps[theFormat]=realloc(theReps[theFormat],length+1);
  46.     NXRead(stream,theReps[theFormat],length);
  47.     *(theReps[theFormat]+length)=0;
  48.     return self;
  49. }
  50.  
  51. // overidden etImage methods
  52. + toolAwake:theApp
  53. {
  54.     char        buf[MAXPATHLEN];
  55.     NXBundle    *bundle;
  56.     id             icon=nil;
  57.  
  58.     bundle = [NXBundle bundleForClass:[eTLiteral class]];
  59.     if ([bundle getPath:buf forResource:"eTLiteralIcon" ofType:"tiff"] ) {
  60.         icon=[[NXImage alloc] initFromFile:buf];
  61.         [icon setName:"eTLiteralIcon"];
  62.     } else {
  63.         NXLogError("Image not found: eTLiteralIcon");
  64.     }    
  65.     [theApp   registerAnnotation: [eTLiteral class] 
  66.                             name: "eTLiteral--HTML"
  67.                     RTFDirective: "eTLiteral"
  68.                        menuLabel: "HTML/Literal Markup"
  69.                          menuKey: '\0'
  70.                         menuIcon: (NXImage *) nil];
  71.     [theApp   registerAnnotation: [eTLiteral class] 
  72.                             name: "eTLiteral--LaTeX"
  73.                     RTFDirective: "eTLiteral"
  74.                        menuLabel: "LaTeX/Literal Markup"
  75.                          menuKey: '\0'
  76.                         menuIcon: (NXImage *) nil];
  77.     [theApp   registerAnnotation: [eTLiteral class] 
  78.                             name: "eTLiteral--C"
  79.                     RTFDirective: "eTLiteral"
  80.                        menuLabel: "C/Literal Markup"
  81.                          menuKey: '\0'
  82.                         menuIcon: (NXImage *) nil];
  83.     // "delegate" chain:
  84.     [eTISINDEXLiteral toolAwake:theApp];
  85.     return self;
  86. }
  87.  
  88. - init
  89. {
  90.     [super init];
  91.     
  92.     [self setImageComponent:[eTImageComponent newImageNamed:"eTLiteralIcon"]];
  93.     [self setUsesButtonStyle:NO];
  94.     [self setDraggable:YES];
  95.     return self;
  96. }
  97.  
  98. - free 
  99. {    
  100.     int i;
  101.     for(i=0;i<[self numReps];i++)
  102.         free(theReps[i]);
  103.     return self = [super free];
  104. }
  105.  
  106. - initFromPboard:thePB inDoc:theDoc linked:(BOOL) linked
  107. {
  108.     //[self init]; called from above.
  109.     [super initFromPboard:thePB inDoc:theDoc linked:linked];
  110.     [imageComponent setDoc:theDoc];
  111.     return self;
  112. }
  113.  
  114. - writeComponentToPath:(NXAtom)path inFormat:(int) theFormat
  115. {
  116.     if(!etDoc)    NXLogError("etDoc is nil at %s %u",__FILE__,__LINE__);
  117.     return [super writeComponentToPath:path inFormat:theFormat];
  118. }
  119. - readRichText:(NXStream *)stream forView:view 
  120. {
  121.     int cnt,i;
  122.     
  123.     NXScanf(stream, "%d ", &i);
  124.     if (i != _eTLiteralVERSION) {
  125.         // bad version block.
  126.         NXLogError("eTLiteral found unparseable version %d at position %d",
  127.                     i, NXTell(stream));
  128.         return nil;
  129.     }
  130.  
  131.     for(cnt=0;cnt<[self numReps];cnt++){
  132.         NXScanf(stream, "%d", &i); NXGetc(stream); //space-eater
  133.         if (i) {
  134.             [self setRep:cnt fromStream: stream length:i];
  135.             NXGetc(stream); // trailing space
  136.         } // if i was zero, we have already advanced to the next non-white bit.
  137.     }
  138.     [super readRichText:stream forView:view];
  139.     return self;
  140. }
  141. - writeRichText:(NXStream *)stream forView:view
  142. {    
  143.     int cnt;
  144.     
  145.     NXPrintf(stream, "%d ", _eTLiteralVERSION);
  146.     for(cnt=0;cnt<[self numReps];cnt++) {
  147.         if (theReps[cnt])
  148.             NXPrintf(stream, "%d %s ",strlen(theReps[cnt]),theReps[cnt]);
  149.         else NXPrintf(stream, "%d  ",0);
  150.     }
  151.     [super writeRichText:stream forView:view];
  152.     return self;
  153. }
  154. - writeASCIIRef:(NXStream *)stream forView:view
  155. {
  156.     if(theReps[ASCII_FMT])
  157.         NXPrintf(stream,"%s",theReps[ASCII_FMT]);
  158.     return self;
  159. }
  160. - writeC:(NXStream *)stream forView:view
  161. {
  162.     if(theReps[C_FMT])
  163.         NXPrintf(stream, "%s",theReps[C_FMT]);
  164.     return self;
  165. }
  166. - writeHTML:(NXStream*)stream forView:view
  167. {            
  168.     if(theReps[HTMD_FMT])
  169.         NXPrintf(stream,"%s",theReps[HTMD_FMT]);
  170.     return self;
  171. }
  172. - writeLaTeX:(NXStream *)stream forView:view
  173. {         
  174.     if(theReps[TeXD_FMT])
  175.         NXPrintf(stream,"%s",theReps[TeXD_FMT]);
  176.     return self;
  177. }
  178. - inspect:(NXEvent *) e
  179. {
  180.     [[NXApp inspector] inspect:self];
  181.     return self;
  182. }
  183. - (id <Inspectable>) inspectableDelegate {
  184.     return [[eTLiteralUI new] setAnnotation:self]; }
  185. @end